<template>
    <div class="financial">
        <van-nav-bar :title="$t('financial.record')" left-arrow @click-left="_return" fixed></van-nav-bar>
        <van-tabs v-model="active" style="margin-top: 40px;">
            <van-tab :title="$t('financial.ord1')">
                <!-- <van-tab :title="$t('financial.ord1')"></van-tab> -->
                <van-tabbar v-model="actives" @change="onChange">
                    <van-tabbar-item >{{$t('financial.ordtype1')}}</van-tabbar-item>
                    <van-tabbar-item >{{$t('financial.ordtype2')}}</van-tabbar-item>
                    <!-- <van-tabbar-item ></van-tabbar-item>
                    <van-tabbar-item ></van-tabbar-item> -->
              </van-tabbar>
                <ul class="newlistbox">
                    <li class="newlist"  v-for="(item, key) in orderDetail" :key="key">
                        <p class="left">{{item.level_name}}</p>
                        <p class="right">年化 <span class="greentips">{{item.annual_earnings}}%</span></p>
                        <div class="clear"></div>
                        <p class="left">存入金额</p>
                        <p class="right greentips">{{item.num}}{{item.coin_name}}</p>
                        <div class="clear"></div>
                        <p class="left">{{getMyDate(item.add_time*1000)}}</p>
                        <p class="right greentips" v-if="item.show_name">{{item.show_name}}</p>
                        <p class="right greentips" v-else>已结束</p>
                        <div class="clear"></div>
                    </li>
                </ul>
            </van-tab>
            <van-tab :title="$t('financial.ord2')">
              <ul class="financial-record-list">
                <li class="financial-record-list-item" v-for="(item, key) in recordDetail" :key="key">
                <div class="financial-record-list-item-desc">
                    <img :src="'http://ht.aat.ink' + item.img" alt="">
                    <div>
                        <p class="financial-record-list-item__label">{{ item.unit }} {{ item.type === 1 ? $t('financial.financial_in') : item.type === 2 ? $t('financial.financial_out') : $t('financial.income') }}</p>
                        <p class="financial-record-list-item__time">{{ item.date }}</p>
                    </div>
                </div>
                <div class="financial-record-list-item-price">
                    {{ item.type === 2 ? '-' : '+' }} {{ item.num }} {{ item.unit }}
                </div>
                </li>
            </ul>
            </van-tab>
        </van-tabs>
        <!-- <ul class="financial-record-list">
            <li class="financial-record-list-item" v-for="(item, key) in recordDetail" :key="key">
                <div class="financial-record-list-item-desc">
                    <img :src="'http://ht.aat.ink' + item.img" alt="">
                    <div>
                        <p class="financial-record-list-item__label">{{ item.unit }} {{ item.type === 1 ? $t('financial.financial_in') : item.type === 2 ? $t('financial.financial_out') : $t('financial.income') }}</p>
                        <p class="financial-record-list-item__time">{{ item.date }}</p>
                    </div>
                </div>
                <div class="financial-record-list-item-price">
                    {{ item.type === 2 ? '-' : '+' }} {{ item.num }} {{ item.unit }}
                </div>
            </li>
        </ul> -->
    </div>
</template>

<script>
    export default {
        data() {
            return {
                recordDetail:[],
                orderDetail:[],
                page:1,
                active:0,
                actives:0,
                ordertype:0
            }
        },
        methods: {
            _return(){
                window.removeEventListener("scroll", this.reachBottom,true)
                this.$emit('_return')
                this.page=1
            },
             onChange(index) {
                 console.log(index)
                 this.orderDetail=[]
                 this.page=1
                 this.ordertype=index
                 this.getDatalist(this.ordertype)
                //  if(index=='0'){
                //      this.getDatalist(0)
                //  }
        },
             getDatalist(index){
                window.addEventListener("scroll", this.reachBottom,true)
                this.$api.gettest('api/bi/orderRecord',{page:this.page,type:index})
                    .then(res =>{
                        if(res.detail.record.length < 10){
                            window.removeEventListener("scroll", this.reachBottom,true)
                        }
                        res.detail.record.forEach(item => this.orderDetail.push(item))
                        this.listNum = res.detail.listNum
                    })
            },
            getData(){
                window.addEventListener("scroll", this.reachBottom,true)
                this.$api.get('bi/record',{page:this.page})
                    .then(res =>{
                        if(res.detail.record.length < 10){
                            window.removeEventListener("scroll", this.reachBottom,true)
                        }
                        res.detail.record.forEach(item => this.recordDetail.push(item))
                        this.listNum = res.detail.listNum
                    })
            },
            getScrollTop () {
                // 考虑到浏览器版本兼容性问题，解析方式可能会不一样
                return document.documentElement.scrollTop || document.body.scrollTop
            },
            getWinHeight () {
                // 浏览器可见内容高度 || 浏览器所有内容高度(考虑到浏览器版本兼容性问题，解析方式可能会不一样)
                return document.documentElement.clientHeight || document.body.clientHeight
            },
            getScrollHeight() {
                let bodyScrollHeight = 0
                let documentScrollHeight = 0
                if (document.body) {
                    bodyScrollHeight = document.body.scrollHeight
                }
                if (document.documentElement) {
                    documentScrollHeight = document.documentElement.scrollHeight
                }
                // 当页面内容超出浏览器可视窗口大小时，Html的高度包含body高度+margin+padding+border所以html高度可能会大于body高度
                return (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight
            },
            isReachBottom () {
                const scrollTop = this.getScrollTop() // 获取滚动条的高度
                const winHeight = this.getWinHeight() // 一屏的高度
                const scrollHeight = this.getScrollHeight() // 获取文档总高度
                return scrollTop >= parseInt(scrollHeight) - winHeight
            },
            reachBottom() {
                if (this.isReachBottom()) {
                    if (this.listNum > 10) {
                        this.page ++
                        this.getData()
                         this.getDatalist(this.ordertype)
                    } else {
                        window.onscroll = null
                    }
                }
            },
      getMyDate(t){
        t = new Date(t)
        var year = t.getFullYear()
        var month = (t.getMonth() + 1)
       
        var date = t.getDate()
       
        var hour = t.getHours()
        hour = this.checkAddZone(hour)
       
        var min = t.getMinutes()
        min = this.checkAddZone(min)

        var se = t.getSeconds()
        se = this.checkAddZone(se)
            month = this.checkAddZone(month)
            date = this.checkAddZone(date)
            return year+'年'+month+'月'+date+'日'+hour + ':' + min + ':' + se
    },
checkAddZone(num) {
    return num<10 ? '0' + num.toString() : num
}
        },
        created() {
            this.getData()
            this.getDatalist(0)
        },
        mounted() {
            window.addEventListener("scroll", this.reachBottom,true)
        },
    }
</script>

<style lang="stylus" scoped>
    [class*=van-hairline]::after{
        border: none;
    }
    .financial {
        /*background-color: #071E57;*/
        .newlist{padding:10px;border:1px solid #ebebeb;margin:20px;margin-top:0px;border-radius:5px}
        .left{float:left}
        .right{float:right}
        .clear{clear:both;margin-bottom:10px}
        .clear:last-child{margin-bottom:0px}
        .greentips{color:rgb(34, 193, 150) !important}
        &-main {
            margin-top: 46px;
            padding: 15px;
            margin-bottom: 60px;

            &-info {
                background:linear-gradient(90deg,rgba(42,42,42,1) 0%,rgba(46,46,46,1) 100%);
                box-shadow:0px 6px 12px 0px rgba(0,0,0,0.5);
                border-radius 5px
                padding: 15px;

                &-top {
                    border-bottom: 1px solid rgba(255, 255, 255, 0.1);

                    &-txt {
                        font-size: 12px;
                        color: #fff;
                    }

                    &-price {
                        font-size: 36px;
                        line-height: 40px;
                        color: #CBAF89;
                        margin-bottom: 8px;
                    }
                }

                &-bottom {
                    margin-top: 12px;
                    display: flex;
                    justify-content: space-between;

                    &-item {
                        &__label {
                            font-size: 12px;
                            color: #fff;
                            height: 16px;
                            line-height: 16px;
                        }

                        &__value {
                            margin-top: 4px;
                            font-size: 18px;
                            color: #CBAF89;
                            height: 22px;
                            line-height: 22px;
                        }

                        &:last-child {
                            text-align: right;
                        }
                    }
                }
            }

            &-list {
                &-item {
                    padding: 12px 15px;
                    background:linear-gradient(90deg,rgba(42,42,42,1) 0%,rgba(46,46,46,1) 100%);
                    margin-top: 10px;
                    border-radius 5px
                    color white
                }

                &-label {
                    display: flex;
                    align-items: center;
                    justify-content: space-between;

                    div {
                        img {
                            width: 30px;
                            height: 30px;
                            vertical-align: middle;
                            margin-right: 3px;
                        }

                        font-size: 14px;

                        &:last-child {
                            opacity: 0.6;
                        }
                    }
                }

                &-value {
                    margin-top: 4px;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    font-size: 24px;

                    .price {
                        color: #CBAF89;
                        margin-right: 2px;
                    }
                }
            }
        }

        &-cur-coin {
            width: 94%;
            margin: 0 auto;
            &-desc {
                padding: 15px;
                background-color: #0E2764;
                box-shadow: 0 2px 20px -6px rgba(0,0,0,0.42);
                &-top {
                    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
                    text-align: center;
                    &__label {
                        position: relative;
                        font-size: 12px;
                        line-height: 16px;
                        .coin-logo {
                            width: 30px;
                            height: 30px;
                            vertical-align: middle;
                            margin-right: 4px;
                        }
                        .eye-icon {
                            position: absolute;
                            top: 0;
                            right: 15px;
                        }
                    }
                    &__value {
                        font-size: 36px;
                        color: #44CEFA;
                        margin-bottom: 8px;
                    }
                }

                &-bottom {
                    margin-top: 13px;
                    &__label {
                        display: flex;
                        justify-content: space-between;
                        font-size: 12px;
                        line-height: 16px;
                    }
                    &__value {
                        display: flex;
                        justify-content: space-between;
                        font-size: 18px;
                        color: #44CEFA;
                        line-height: 22px;
                    }
                }
            }

            &-chart {
                margin-top: 40px;
                &-title {
                    text-align: center;
                    font-size: 36px;
                    color: #44CEFA;
                    line-height: 40px;
                }
                &-desc {
                    text-align: center;
                    font-size: 12px;
                    line-height: 16px;
                    opacity: 0.6;
                }
            }
        }
        &-turn-out, &-turn-in, &-record-list {
            padding: 60px 15px;
        }
        &-record-list {
            &-item {
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 12px 10px;
                background-color: none;
                margin-bottom: 5px;
                border-bottom:1px solid #ebebeb
                &-desc {
                    display: flex;
                    align-items: center;
                    img {
                        width: 30px;
                        height: 30px;
                        margin-right: 5px;
                    }
                }
                &__label {
                    font-size: 14px;
                }
                &__time {
                    font-size: 12px;
                    opacity: 0.6;
                }
            }
        }

        &-turn-out, &-turn-in {
            &-info {
                background-color: #0E2764;
                padding: 12px 10px;
                display: flex;
                justify-content: space-between;

                &-wrap {
                    display: flex;
                    align-items: center;
                    img {
                        width: 30px;
                        height: 30px;
                        margin-right: 10px;
                    }
                }
                &-label {
                    font-size: 12px;
                    line-height: 16px;
                }
                &-value {
                    font-size: 14px;
                    color: #44CEFA;
                    line-height: 20px;
                }
            }
            &-inp {
                margin-top: 10px;
                background-color: #0E2764;
                padding: 10px;
                font-size: 14px;
                .van-cell.van-field {
                    margin-top: 20px;
                    background-color: #0E2764!important;
                    padding: 0;
                    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
                    .van-button {
                        border: none;
                        background-color: #0E2764;
                        color: #44CEFA;
                        &:active::before {
                            background-color: #0E2764;
                        }
                    }
                }
            }
            &-btn {
                margin-top: 20px;
                border: none;
                background-color: #4BC5F9;
                width: 100%;
                height: 44px;
                border-radius: 22px;
                color: #fff;
            }
        }

        &-turn-coin {
            &-header {
                height: 75px;
                line-height: 75px;
                display: flex;
                justify-content: space-between;
                align-items: center;

                .van-icon.van-icon-arrow-left {
                    font-size: 20px;
                }
            }
        }
        &-pay-pwd {
            height: 100%;
            background: #0E2764;

            &-tip {
                text-align: center;
                color: #FFD63B;
                font-size: 12px;
                margin-top: 10px;
                background:linear-gradient(90deg,#53d9b5,#2bc299);
            }

            &-btn {
                display: flex;
                justify-content: center;
                margin-top: 170px;
                padding-bottom: 15px;

                .van-button {
                    width: 96%;
                    border-radius: 22px;
                    color: #fff;
                    border: none;
                    background-color: #4BC5F9;
                }
            }
        }

        &-footer {
            position: fixed;
            left: 0;
            bottom: 0;
            width: 100%;
            box-sizing: border-box;
            background:linear-gradient(90deg,rgba(42,42,42,1) 0%,rgba(46,46,46,1) 100%);
            box-shadow:0px -2px 20px -6px rgba(0,0,0,0.42);
            padding: 8px 10px;
            display: flex;
            justify-content: space-between;

            &-btn {
                border: none;
                padding: 0 70px;
                height: 44px;
                border-radius: 5px;
                color: #1F1F1F;
                background:linear-gradient(90deg,rgba(203,175,137,1) 0%,rgba(219,200,170,1) 100%);

                &:first-child {
                    background:rgba(216,216,216,1);
                }
            }
        }

        .van-popup {
            height: 50%;
        }
        .van-tabbar--fixed{
            top :55px;
            width :50%;
            position :absolute;

        }
        .newlistbox{
            margin-top:70px!important
            }
    }
</style>